package io.gitee.zhangbinhub.acp.boot.tools

import io.gitee.zhangbinhub.acp.boot.exceptions.ErrorResult
import io.gitee.zhangbinhub.acp.boot.vo.ErrorVo
import io.gitee.zhangbinhub.acp.core.common.CommonTools
import org.springframework.http.HttpStatus

/**
 * Created by Shepherd on 2016-08-05.
 * 报文消息工具类
 */
object PackageTools {
    /**
     * 构建响应报文
     *
     * @param httpStatus 响应状态
     * @param detail     响应信息
     * @return 响应报文JSON对象
     */
    @JvmStatic
    fun buildErrorResult(httpStatus: HttpStatus, detail: String?): ErrorResult {
        var message = detail
        if (CommonTools.isNullStr(message)) {
            message = httpStatus.reasonPhrase
        }
        return ErrorResult(
            httpStatus,
            ErrorVo(code = httpStatus.value(), error = httpStatus.reasonPhrase, errorDescription = message)
        )
    }
}
